package exchange.direct;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Producer {

	private static final String EXECHANGE_NAME = "logs1";
	
	public static void main(String[] args) {
		try {
			ConnectionFactory factory = new ConnectionFactory();
			factory.setHost("localhost");
			Connection connect = factory.newConnection();
			Channel channel = connect.createChannel();
			channel.exchangeDeclare(EXECHANGE_NAME,"direct");
			for(int i = 0;i<5;i++) {
				String message = "交换器消息======"+i;
				channel.basicPublish(EXECHANGE_NAME,"abc",null,message.getBytes());
				System.out.println(" [x] Sent '" + message + "'");
			}
			for(int i = 0;i<5;i++) {
				String message = "交换器消息2======"+i;
				channel.basicPublish(EXECHANGE_NAME,"def",null,message.getBytes());
				System.out.println(" [x] Sent '" + message + "'");
			}
			channel.close();
			connect.close();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (TimeoutException e) {
			e.printStackTrace();
		}
		
	}
}
